home *** CD-ROM | disk | FTP | other *** search
- Path: beach.and.nl!usenet
- From: jos@and.nl (Jos A. Horsmeier)
- Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland
- Subject: Re: Tough FACTORIAL math problem...
- Date: 15 Feb 1996 17:35:18 GMT
- Organization: AND Operations Research B.V.
- Message-ID: <4fvqsm$dfm@beach.and.nl>
- References: <4fr8be$ass@news.iconn.net> <wzenrwg142.fsf@stego.cs.ruu.nl> <4fvorm$dfm@beach.and.nl>
- NNTP-Posting-Host: klepzeiker.and.nl
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4fvorm$dfm@beach.and.nl>, jos@and.nl goofed:
- |In article <wzenrwg142.fsf@stego.cs.ruu.nl>, piet@stego.cs.ruu.nl wrote:
-
- ||A little thinking before coding solves this problem very easily:
- ||
- ||Let N be then number whose factorial you are considering.
- ||
- ||What you want is the number of trailing zeroes + 1.
- |
- |[ clever solution of not-the-posters-problem deleted ... ]
- |
- |No, that's not what he wanted. A little reading before thinking before
- |coding may come in handy sometimes ;-) What the original poster wants
- |is the value of the rightmost non-zero digit of n!.
- |
- |Let D(n) be the value of the rightmost non-zero digit of number n,
- |it is easy to show that D(n!)= D(D(n)*D((n-1)!). Here's function D,
- |written in C (it still is c.l.c isn't it?)
-
- And a bit of thinking-before-reading-before-thinking-before-coding
- is even better most of the times ... darn, I must've had my brains all
- backwards; please forget my previous follow-up ... boy, do I feel silly.
-
- kind regards,
-
- Jos aka jos@and.nl (blushing)
- --
- Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
-
-